file_name = 'guest_book.txt'
with open(file_name, 'w') as file_object:
    flag = 1
    while flag:
        print('You can enter "b" to end!')
        guest_name = input('Please enter your name: ')
        if guest_name == 'b':
            flag = 0
        else:
            print('Hello!' + guest_name + '.')
            file_object.write(guest_name + '\n')
